//
//  CZRetweetView.swift
//  git
//
//  Created by 徐 鹏超 on 16/4/13.
//  Copyright © 2016年 徐 鹏飞. All rights reserved.
//

import UIKit
import SnapKit
class CZRetweetView: UIView {
    
    var constarit: Constraint?
    // 定义转发微博的内容
    var retweetStatus: CZStatusModel?{
        
        didSet{
            
            contentLabel.text = retweetStatus?.retweeted_status?.text
            
            constarit?.uninstall()
            
            // 根据数据来判断是否显示配图 -> 转发微博的配图在 转发对象的pic_urls
            if let pic_urls = retweetStatus?.retweeted_status?.pic_urls where pic_urls.count > 0{
                //                printLog("有配图")
                pictureView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    constarit = make.bottom.equalTo(pictureView.snp_bottom).constraint
                })
                
                // 赋值
                pictureView.pic_urls = pic_urls
                
            } else {
                //                printLog("没有配图")
                pictureView.hidden = true
                
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    constarit = make.bottom.equalTo(contentLabel.snp_bottom).constraint
                })
            }
            
        }
        
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(contentLabel)
        addSubview(pictureView)
        
        pictureView.backgroundColor = UIColor.yellowColor()
        
        // 约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            // 一定要记得,自动计算行高的时候,设置底部约束
//            make.bottom.equalTo(self.snp_bottom)
            
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(contentLabel.snp_bottom)
            
            
            //固定的宽高
            make.width.height.equalTo(100)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            constarit =  make.bottom.equalTo(pictureView.snp_bottom).constraint
        }

    }
    
    
    //MARK:--懒加载
    private lazy var contentLabel: UILabel = {
        
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(14)
        
        label.textColor = UIColor.greenColor()
        
        label.text = "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博"
        
        label.numberOfLines = 0
        
        return label
    }()

    private lazy var pictureView: CZPictureView = CZPictureView()
}
